home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / f1ocx / vcform1.3 / VB4 / SSMDI / SSMDI.BAS < prev    next >
Encoding:
BASIC Source File  |  1995-09-15  |  25.2 KB  |  791 lines

  1. Attribute VB_Name = "SSMDI1"
  2. Option Explicit
  3.  
  4. '' This variable is used to name the worksheets in each
  5. '' child window.
  6. Global gNewSSCount As Integer
  7.  
  8. '' These variables are used for the color controls on the toolbar
  9. Global TextOrFillColorFlag As Integer
  10. Global CurrentFillColorIndex As Integer
  11. Global CurrentTextColorIndex As Integer
  12.  
  13. '' These are used for the Format Painter command
  14. Global FormatPainterFlag As Integer
  15. Global FmtPntStartRow As Integer
  16. Global FmtPntEndRow As Integer
  17. Global FmtPntStartCol As Integer
  18. Global FmtPntEndCol As Integer
  19.  
  20.  
  21. '' Used for reading metafiles
  22. Type Rect
  23.     bbLeft As Integer
  24.     bbTop As Integer
  25.     bbRight As Integer
  26.     bbBottom As Integer
  27. End Type
  28.  
  29. Type APMFILEHEADER
  30.     key As Long
  31.     hmf As Integer
  32.     bbox As Rect
  33.     inch As Integer
  34.     reserved As Long
  35.     checksum As Integer
  36. End Type
  37.  
  38. Sub AddDecimalPlace(AddingDigits As Integer)
  39.  
  40.     Dim TheFormat As String, TheNewFormat As String, TheChar As String
  41.     Dim TheFormatLen As Integer, FromPointer As Integer
  42.     Dim DecimalPointFound As Integer, ScientificFound As Integer
  43.     Dim SS As Object
  44.  
  45.  
  46.     ' This routine parses the format strings associated with the selected cell
  47.     ' and either adds or subtracts a decimal place depending on the setting of
  48.     ' AddingDigits.  It is not internationalized and will only work with
  49.     ' American settings (i.e. period for decimal, comma for thousands).
  50.     
  51.     ' If no active sheet then don't do anything
  52.     If Not (MainFrame.ActiveForm Is Nothing) Then
  53.  
  54.         ' Save the object into a variable to save on typing.
  55.         Set SS = MainFrame.ActiveForm.SS
  56.  
  57.         ' Get the format for the active cell.
  58.         TheFormat = SS.NumberFormat
  59.         
  60.         ' Don't handle the percentage formats
  61.         If TheFormat = "# ?/?" Or TheFormat = "# ??/??" Then
  62.             Beep
  63.             SS.SetFocus
  64.             Exit Sub
  65.         End If
  66.         
  67.         ' FromPointer is moved through the original string one character at a time.  Format
  68.         ' characters are copied to TheNewFormat and special cases handled individually.
  69.         
  70.         TheFormatLen = Len(TheFormat)
  71.         FromPointer = 1
  72.         
  73.         While FromPointer <= TheFormatLen
  74.         
  75.             TheChar = Mid$(TheFormat, FromPointer, 1)
  76.  
  77.             ' Process numbers
  78.             If TheChar = "0" Or TheChar = "#" Then
  79.                 
  80.                 ' If adding digits then find the decimal or add one if there is none
  81.                 If AddingDigits = True Then
  82.                     DecimalPointFound = False
  83.                     ScientificFound = False
  84.                     Do While FromPointer <= TheFormatLen
  85.                         TheChar = Mid$(TheFormat, FromPointer, 1)
  86.                         If TheChar = "." Then DecimalPointFound = True
  87.                         If TheChar = "E" Or TheChar = "e" Then ScientificFound = True
  88.                         If TheChar <> "0" And TheChar <> "#" And TheChar <> "." And TheChar <> "," Then Exit Do
  89.                         TheNewFormat = TheNewFormat + TheChar
  90.                         FromPointer = FromPointer + 1
  91.                     Loop
  92.     
  93.                     ' Add the decimal point if it didn't have one before
  94.                     If Not DecimalPointFound Then
  95.                         TheNewFormat = TheNewFormat + "."
  96.                     End If
  97.     
  98.                     ' Now add the new decimal place and we're done
  99.                     TheNewFormat = TheNewFormat + "0"
  100.                 
  101.                 ' Removing Digits
  102.                 Else
  103.                     DecimalPointFound = 0
  104.                     ScientificFound = False
  105.                     Do While FromPointer <= TheFormatLen
  106.                         TheChar = Mid$(TheFormat, FromPointer, 1)
  107.                         If TheChar = "." Then DecimalPointFound = Len(TheNewFormat) + 1
  108.                         If TheChar = "E" Or TheChar = "e" Then ScientificFound = True
  109.                         If TheChar <> "0" And TheChar <> "#" And TheChar <> "." And TheChar <> "," Then Exit Do
  110.                         TheNewFormat = TheNewFormat + TheChar
  111.                         FromPointer = FromPointer + 1
  112.                     Loop
  113.  
  114.                     If DecimalPointFound = 0 Then
  115.                         Beep
  116.                     Else
  117.                         ' Remove the rightmost character (either a 0 or a ".")
  118.                         TheNewFormat = Left$(TheNewFormat, Len(TheNewFormat) - 1)
  119.                         ' If there's only a decimal point left at the end, remove it
  120.                         If Right$(TheNewFormat, 1) = "." Then
  121.                             TheNewFormat = Left$(TheNewFormat, Len(TheNewFormat) - 1)
  122.                         End If
  123.                     End If
  124.                 End If
  125.                 
  126.                 ' If we weren't at the end of the string, add the last character on
  127.                 If FromPointer <= TheFormatLen Then
  128.                     TheNewFormat = TheNewFormat + TheChar
  129.                 End If
  130.                 
  131.                 ' If scienticic notation, then skip the rest of this number format
  132.                 If ScientificFound Then
  133.                     Do While FromPointer <= TheFormatLen
  134.                         FromPointer = FromPointer + 1
  135.                         TheChar = Mid$(TheFormat, FromPointer, 1)
  136.                         TheNewFormat = TheNewFormat + TheChar
  137.                         If TheChar <> "0" And TheChar <> "+" And TheChar <> "-" Then Exit Do
  138.                     Loop
  139.                 End If
  140.                 
  141.             ' Skip everything in the boxes (Colors or Conditionals)
  142.             ElseIf TheChar = "[" Then
  143.                 Do While FromPointer <= TheFormatLen
  144.                     TheChar = Mid$(TheFormat, FromPointer, 1)
  145.                     TheNewFormat = TheNewFormat + TheChar
  146.                     If TheChar = "]" Then Exit Do
  147.                     FromPointer = FromPointer + 1
  148.                 Loop
  149.             
  150.             'Skip everything in quotes
  151.             ElseIf TheChar = Chr$(34) Then
  152.                 Do While FromPointer <= TheFormatLen
  153.                     TheChar = Mid$(TheFormat, FromPointer, 1)
  154.                     TheNewFormat = TheNewFormat + TheChar
  155.                     If TheChar = Chr$(34) Then Exit Do
  156.                     FromPointer = FromPointer + 1
  157.                 Loop
  158.             
  159.             ' Copy the "\" or "_" and the next character without change
  160.             ElseIf TheChar = "_" Or TheChar = "\" Then
  161.                 TheNewFormat = TheNewFormat + TheChar
  162.                 FromPointer = FromPointer + 1
  163.                 TheChar = Mid$(TheFormat, FromPointer, 1)
  164.                 TheNewFormat = TheNewFormat + TheChar
  165.             
  166.             ' All other characters are copied across without changing
  167.             Else
  168.                 TheNewFormat = TheNewFormat + TheChar
  169.             End If
  170.  
  171.             FromPointer = FromPointer + 1
  172.         Wend
  173.         
  174.         
  175.         ' Handle General format separately
  176.         If TheNewFormat = "General" Then
  177.             If AddingDigits = True Then
  178.                 TheNewFormat = "0.0"
  179.             Else
  180.                 Beep
  181.             End If
  182.         End If
  183.         
  184.         ' Set the decimal places for each cell.
  185.         SS.NumberFormat = TheNewFormat
  186.  
  187.     End If
  188.  
  189.     SS.SetFocus
  190.  
  191. End Sub
  192.  
  193. Sub C_AutoSum()
  194.  
  195.    Dim OldRow1%, OldRow2%, OldCol1%, OldCol2%, OldRow%, OldCol%
  196.    Dim TheRow%, TheCol%, TheType%
  197.    Dim TheFormula$
  198.  
  199.    '' This function partly emulates the function of Excel's AutoSum command.  It automatically
  200.    '' creates a formula that sums the cells above it.  If a range is selected then it will
  201.    '' automatically fill the range with the new sum formula.
  202.  
  203.    '' Unlike Excel, it only sums cells above it (and not to the left).  This extension could
  204.    '' easily be added using the simple framework below.
  205.     
  206.    If SSIsActiveForm() Then  ' Make sure there is an active worksheet
  207.         
  208.       '' Save the original range information for later
  209.       OldRow = MainFrame.ActiveForm.SS.Row            '' Current Row
  210.       OldCol = MainFrame.ActiveForm.SS.Col            '' Current Column
  211.       OldRow1 = MainFrame.ActiveForm.SS.SelStartRow   '' Current Selection
  212.       OldRow2 = MainFrame.ActiveForm.SS.SelEndRow     '' "
  213.       OldCol1 = MainFrame.ActiveForm.SS.SelStartCol   '' "
  214.       OldCol2 = MainFrame.ActiveForm.SS.SelEndCol     '' "
  215.         
  216.       TheRow = OldRow ' Get the row and colum of the current cell
  217.       TheCol = OldCol ' so we can look above it for a range to sum
  218.         
  219.       If TheRow = 1 Then  ' Can't do it if this is row 1
  220.          Beep
  221.          Exit Sub
  222.         
  223.       Else
  224.             
  225.          '' Look above this cell for numbers or formulas returning numbers.  Ignore all blank cells.
  226.             
  227.          TheRow = TheRow - 1
  228.          Do
  229.             TheType = MainFrame.ActiveForm.SS.TypeRC(TheRow, TheCol)
  230.             If Abs(TheType) = 1 Then  ' 1 (Number) or -1 (Number Formula) are valid cell types to sum
  231.                Exit Do
  232.             ElseIf Abs(TheType) > 1 Then ' Not a valid type (text, error, logical) so return error
  233.                Beep
  234.                Exit Sub
  235.             End If
  236.                 
  237.             TheRow = TheRow - 1
  238.                 
  239.             If TheRow < 1 Then ' If we made it to the top and have not found a number cell then error
  240.                Beep
  241.                Exit Sub
  242.             End If
  243.          Loop
  244.             
  245.          '' We found the first number cell, now keep moving up until a non-numeric cell is found
  246.          Do While TheRow > 0
  247.             TheType = MainFrame.ActiveForm.SS.TypeRC(TheRow, TheCol)
  248.             If Abs(TheType) <> 1 Then  ' 1 (Number) or -1 (Number Formula) are valid cell types to sum
  249.                Exit Do
  250.             End If
  251.                TheRow = TheRow - 1
  252.          Loop
  253.             
  254.          '' Create a new selection based on the range we just found
  255.          MainFrame.ActiveForm.SS.SelStartRow = TheRow + 1
  256.          MainFrame.ActiveForm.SS.SelEndRow = OldRow - 1
  257.          MainFrame.ActiveForm.SS.SelStartCol = OldCol1
  258.          MainFrame.ActiveForm.SS.SelEndCol = OldCol1
  259.             
  260.          '' The Selection property contains a string representation of the selection
  261.          TheFormula = "Sum(" + MainFrame.ActiveForm.SS.Selection + ")"
  262.             
  263.          '' Put the new sum into the first cell in the range
  264.          MainFrame.ActiveForm.SS.Row = OldRow1
  265.          MainFrame.ActiveForm.SS.Col = OldCol1
  266.          MainFrame.ActiveForm.SS.Formula = TheFormula
  267.         
  268.          '' Put everything back the way we started
  269.          MainFrame.ActiveForm.SS.Row = OldRow
  270.          MainFrame.ActiveForm.SS.Col = OldCol
  271.          MainFrame.ActiveForm.SS.SelStartRow = OldRow1
  272.          MainFrame.ActiveForm.SS.SelEndRow = OldRow2
  273.          MainFrame.ActiveForm.SS.SelStartCol = OldCol1
  274.          MainFrame.ActiveForm.SS.SelEndCol = OldCol2
  275.  
  276.          '' Copy the formula right to fill the range (the range may only be one cell)
  277.          '' Formula cell references will adjust automatically
  278.          MainFrame.ActiveForm.SS.EditCopyRight
  279.         
  280.       End If
  281.    End If
  282.  
  283. End Sub
  284.  
  285. Sub C_Clear()
  286.  
  287.    '' Clear the current worksheet
  288.    On Error Resume Next
  289.    If SSIsActiveForm() Then
  290.       MainFrame.ActiveForm.SS.EditClear (F1ClearAll)
  291.    End If
  292.  
  293. End Sub
  294.  
  295. Sub C_Copy()
  296.  
  297.    If SSIsActiveForm() Then
  298.       Call ShowSSError(MainFrame.ActiveForm.SS.EditCopy)
  299.    End If
  300.  
  301. End Sub
  302.  
  303. Sub C_Cut()
  304.  
  305.    If SSIsActiveForm() Then
  306.       Call ShowSSError(MainFrame.ActiveForm.SS.EditCut)
  307.    End If
  308.  
  309. End Sub
  310.  
  311. Sub C_New()
  312.    
  313.    On Error GoTo CantCreateNewOne
  314.    Dim SS As New VCIChildForm       '' Create a new worksheet and
  315.    SS.Visible = True                '' make it visible
  316.    Exit Sub
  317.  
  318. CantCreateNewOne:
  319.    MsgBox "Unable to create new worksheet."
  320.  
  321. End Sub
  322.  
  323. Sub C_Paste()
  324.  
  325.    If SSIsActiveForm() Then
  326.       Call ShowSSError(MainFrame.ActiveForm.SS.EditPaste)
  327.    End If
  328.  
  329. End Sub
  330.  
  331. Sub C_Print()
  332.  
  333.    If SSIsActiveForm%() Then
  334.       Call ShowSSError(MainFrame.ActiveForm.SS.FilePrint(True))
  335.    End If
  336.  
  337. End Sub
  338.  
  339. Sub C_Save()
  340.  
  341.    If SSIsActiveForm() Then
  342.       If Left(MainFrame.ActiveForm.SS.TableName, 5) = "Sheet" Then
  343.          Call SSMDISaveAsFile
  344.       Else
  345.          On Error GoTo CantSave
  346.          MainFrame.ActiveForm.SS.Write MainFrame.ActiveForm.SS.TableName, MainFrame.ActiveForm.SS.Tag
  347.          Exit Sub
  348. CantSave:
  349.          MsgBox "Unable to save " & MainFrame.ActiveForm.SS.TableName
  350.          Exit Sub
  351.       End If
  352.    End If
  353.  
  354. End Sub
  355.  
  356. Sub C_Sort(ascending%)
  357.  
  358.    Dim Srow1%, Srow2%, Scol1%, Scol2%, key1%, key2%, Key3%
  359.  
  360.    If SSIsActiveForm() Then
  361.       Srow1 = MainFrame.ActiveForm.SS.SelStartRow
  362.       Srow2 = MainFrame.ActiveForm.SS.SelEndRow
  363.       Scol1 = MainFrame.ActiveForm.SS.SelStartCol
  364.       Scol2 = MainFrame.ActiveForm.SS.SelEndCol
  365.       key1 = 1
  366.       key2 = 1
  367.       Key3 = 1
  368.       If Scol2 - Scol1 > 0 Then key2 = 2
  369.       If Scol2 - Scol1 > 1 Then Key3 = 3
  370.         
  371.       If Not ascending Then
  372.          key1 = -key1
  373.          key2 = -key2
  374.          Key3 = -Key3
  375.       End If
  376.       Call ShowSSError(MainFrame.ActiveForm.SS.Sort3(Srow1, Scol1, Srow2, Scol2, True, key1, key2, Key3))
  377.    End If
  378.  
  379. End Sub
  380.  
  381.  
  382. Sub LayoutToolBars()
  383.  
  384.     Dim NumBars%
  385.     Dim NewTop%
  386.     Dim Barheight
  387.  
  388.  
  389. '' This procedure lays out the toolbars depending on which ones are turned on.
  390.  
  391.     NumBars = Abs(MainFrame.ViewOBT.Checked + MainFrame.ViewFMT.Checked + MainFrame.ViewFOT.Checked)
  392.     
  393.     Barheight = MainFrame.Panel3D1.Height
  394.     NewTop = 0
  395.     
  396.     ' File Open Toolbar
  397.     If MainFrame.ViewFOT.Checked Then
  398.         MainFrame.Panel3D1.Visible = True
  399.         MainFrame.Panel3D1.Width = MainFrame.Width
  400.         MainFrame.Panel3D1.Top = NewTop
  401.         MainFrame.Panel3D1.Left = 0
  402.         NewTop = NewTop + MainFrame.Panel3D1.Height + 5
  403.     End If
  404.     
  405.     ' Object Toolbar
  406.     If MainFrame.ViewOBT.Checked Then
  407.         MainFrame.Panel3D5.Visible = True
  408.         MainFrame.Panel3D5.Width = MainFrame.Width
  409.         MainFrame.Panel3D5.Top = NewTop
  410.         MainFrame.Panel3D5.Left = 0
  411.         NewTop = NewTop + MainFrame.Panel3D5.Height + 5
  412.     End If
  413.     
  414.     ' Formatting Toolbar
  415.     If MainFrame.ViewFMT.Checked Then
  416.         MainFrame.Panel3D3.Visible = True
  417.         MainFrame.Panel3D3.Width = MainFrame.Width
  418.         MainFrame.Panel3D3.Top = NewTop
  419.         NewTop = NewTop + MainFrame.Panel3D3.Height + 5
  420.     End If
  421.     
  422.     ' Adjust size of toolbar frame
  423.     MainFrame.Picture1.Height = NewTop + 50
  424.  
  425. End Sub
  426.  
  427. Sub Paint_Reference()
  428.  
  429.    'MainFrame.RCLabel = MainFrame.ActiveForm.SS.Selection
  430.  
  431. End Sub
  432.  
  433. Sub SetBorderStyle(TheStyle As Integer)
  434.  
  435.     Dim nOutline%, nLeft%, nRight%, nTop%, nBottom%, nShade%
  436.     Dim crOutline&, crLeft&, crRight&, crTop&, crBottom&
  437.     Dim SS As Object
  438.     
  439.     ' This routine sets the border style of the current selection.  The border
  440.     ' style is passed in through TheStyle.
  441.     
  442.     ' Get a handle to the current spreadsheet to save typing.
  443.     Set SS = MainFrame.ActiveForm.SS
  444.     
  445.     ' Set all sides to "Don't Change" (-1 means don't change it)
  446.     nOutline = -1
  447.     nLeft = -1
  448.     nRight = -1
  449.     nTop = -1
  450.     nBottom = -1
  451.     nShade = -1
  452.     
  453.     ' Set the color of the new borders to Black
  454.     crOutline = 0
  455.     crTop = 0
  456.     crBottom = 0
  457.     crLeft = 0
  458.     crRight = 0
  459.     
  460.     ' Set the outline for selected cells
  461.     Select Case TheStyle
  462.     
  463.         Case 0 ' None
  464.             nOutline = 0
  465.             nLeft = 0
  466.             nRight = 0
  467.             nTop = 0
  468.             nBottom = 0
  469.             
  470.         Case 1 ' Bottom
  471.             nBottom = 1 ' Single Thin Line
  472.             
  473.         Case 2 ' Left
  474.             nLeft = 1 ' Single Thin Line
  475.             
  476.         Case 3 ' Right
  477.             nRight = 1 ' Single Thin Line
  478.             
  479.         Case 4 ' Double Thin Bottom
  480.             nBottom = 6 ' Double Thin Lines
  481.             
  482.         Case 5 ' Single Medium Bottom
  483.             nBottom = 2 ' Single Medium Line
  484.             
  485.         Case 6 ' Top/Bottom thin lines
  486.             nTop = 1 ' Single Thin Line
  487.             nBottom = 1 ' Single Thin Line
  488.             
  489.         Case 7 ' Top Thin, Bottom Double Thin
  490.             nTop = 1 ' Single Thin Line
  491.             nBottom = 6 ' Double Thin Lines
  492.         
  493.         Case 8 ' Top Thin, Bottom Medium
  494.             nTop = 1 ' Single Thin Line
  495.             nBottom = 2 ' Single Medium Line
  496.         
  497.         Case 9 ' Outline with separators
  498.             nTop = 1 ' Single Thin Line
  499.             nBottom = 1 ' Single Thin Line
  500.             nLeft = 1 ' Single Thin Line
  501.             nRight = 1 ' Single Thin Line
  502.         
  503.         Case 10 ' Outline Thin
  504.             nOutline = 1 ' Single Thin Line
  505.         
  506.         Case 11 ' Outline Medium
  507.             nOutline = 2 ' Single Medium Line
  508.         
  509.     End Select
  510.     
  511.     ' Set the new border
  512.     SS.SetBorder nOutline, nLeft, nRight, nTop, nBottom, nShade, crOutline, crLeft, crRight, crTop, crBottom
  513.     
  514.     ' Clean up
  515.     BorderForm.Hide
  516.     SS.SetFocus
  517.  
  518. End Sub
  519.  
  520. Sub SetObjectColor(ThePaletteEntry As Integer)
  521.  
  522.     Dim fColor As Long
  523.     Dim bColor As Long
  524.     Dim ThePattern As Integer
  525.     Dim TheRow As Integer, TheCol As Integer
  526.     Dim ObjectCount As Integer
  527.     Dim TheObjectCount As Integer
  528.     Dim TheObjectID As Long
  529.     Dim TheObjectType As Integer
  530.     Dim StartRow As Integer, EndRow As Integer, StartCol As Integer, EndCol As Integer
  531.     Dim SS As Object
  532.     
  533.     ' These are for the object descriptions
  534.     Dim TheStyle As Integer
  535.     Dim TheColor As Long
  536.     Dim TheWeight As Integer
  537.     
  538.     ' These are for the font description of a cell
  539.     Dim pFont As String
  540.     Dim pSize As Integer
  541.     Dim pBold As Boolean
  542.     Dim pItalic As Boolean
  543.     Dim pUnderline As Boolean
  544.     Dim pStrikeout As Boolean
  545.     Dim pcrColor As Long
  546.     Dim pOutline As Boolean
  547.     Dim pShadow As Boolean
  548.  
  549.     '' This procedure changes the foreground color of the currently selected
  550.     '' object.  The object may be the font color, or a drawing object like a
  551.     '' line or rectangle, or it may be the foreground of the cells in the
  552.     '' current selection.
  553.     
  554.     '' Multiple objects are handled, but multiple selections are not.  Therefore,
  555.     '' if there is more than one cell selection, only the current selection
  556.     '' will be changed.  Multiple selections can easily be added if you like.
  557.     
  558.     '' If the object we are operating on is a cell, there is a global flag
  559.     '' called 'TextOrFillColorFlag' that determines whether we are changing
  560.     '' the cell text color or the cell pattern color.
  561.  
  562.     ' If no active sheet then don't do anything
  563.     If Not (MainFrame.ActiveForm Is Nothing) Then
  564.         
  565.         ' Save the object into a variable to save on typing.
  566.         Set SS = MainFrame.ActiveForm.SS
  567.             
  568.         ' Turn off the Selection Change Event so we don't do all the
  569.         ' toolbar updating while formatting.
  570.         SS.DoSelChange = False
  571.         
  572.         '' This section handles the drawing objects.
  573.         
  574.         ' If there are no cell selections then see if there are object selections
  575.         If SS.SelectionCount = 0 Then
  576.             TheObjectCount = SS.ObjGetSelectionCount
  577.             If TheObjectCount > 0 Then
  578.                 For ObjectCount = 1 To TheObjectCount
  579.                     SS.ObjGetSelection ObjectCount - 1, TheObjectID
  580.                     TheObjectType = SS.ObjGetType(TheObjectID)
  581.                     
  582.                     ' If it's a line then change the line color
  583.                     If TheObjectType = F1ObjLine Then
  584.                         SS.GetLineStyle TheStyle, TheColor, TheWeight
  585.                         TheColor = SS.PaletteEntry(ThePaletteEntry)
  586.                         SS.SetLineStyle TheStyle, TheColor, TheWeight
  587.                     
  588.                     ' If it's a filled object, change the fill coloe
  589.                     ElseIf TheObjectType = F1ObjArc Or TheObjectType = F1ObjOval Or TheObjectType = F1ObjPolygon Or TheObjectType = F1ObjRectangle Then
  590.                         SS.GetPattern ThePattern, fColor, bColor
  591.                         fColor = SS.PaletteEntry(ThePaletteEntry)
  592.                         SS.SetPattern ThePattern, fColor, bColor
  593.                     End If
  594.                 
  595.                 Next ObjectCount
  596.             End If
  597.         
  598.         '' This section handles cell selections
  599.         
  600.         Else
  601.             ' Get the selection coordinates.  We have to look at each cell individually.
  602.             StartRow = SS.SelStartRow
  603.             EndRow = SS.SelEndRow
  604.             StartCol = SS.SelStartCol
  605.             EndCol = SS.SelEndCol
  606.     
  607.             ' Set the selection back to a single cell.
  608.             SS.SelStartRow = SS.Row
  609.             SS.SelStartCol = SS.Col
  610.             SS.SelEndRow = SS.Row
  611.             SS.SelEndCol = SS.Col
  612.     
  613.             ' Set the foreground color or text color of each cell.
  614.             ' If setting the fill color and the cell has no pattern
  615.             ' then set the pattern to 1 (solid).
  616.             For TheRow = StartRow To EndRow
  617.                 For TheCol = StartCol To EndCol
  618.                     SS.Row = TheRow
  619.                     SS.Col = TheCol
  620.                     If TextOrFillColorFlag = 0 Then '' Set Fill Color
  621.                         SS.GetPattern ThePattern, fColor, bColor
  622.                         ThePattern = IIf(ThePattern = 0, 1, ThePattern)
  623.                         fColor = SS.PaletteEntry(ThePaletteEntry)
  624.                         SS.SetPattern ThePattern, fColor, bColor
  625.                     Else '' Set Text Color
  626.                         SS.GetFont pFont, pSize, pBold, pItalic, pUnderline, pStrikeout, pcrColor, pOutline, pShadow
  627.                         pcrColor = SS.PaletteEntry(ThePaletteEntry)
  628.                         SS.SetFont pFont, -pSize, pBold, pItalic, pUnderline, pStrikeout, pcrColor, pOutline, pShadow
  629.                     End If
  630.                 Next TheCol
  631.             Next TheRow
  632.     
  633.             ' Restore selection
  634.             SS.SelStartRow = StartRow
  635.             SS.SelEndRow = EndRow
  636.             SS.SelStartCol = StartCol
  637.             SS.SelEndCol = EndCol
  638.             SS.Row = StartRow
  639.             SS.Col = StartCol
  640.         End If
  641.     
  642.     SS.DoSelChange = False
  643.     SS.SetFocus
  644.     
  645.     End If
  646.     
  647. End Sub
  648.  
  649. Sub ShowSSError(ByVal Er As Integer)
  650.    
  651.    Dim ssError As String
  652.  
  653.    If Er <> 0 And Er <> 23 Then
  654.       ssError = Space$(256)
  655.       ssError = MainFrame.ActiveForm.SS.ErrorNumberToText(Er)
  656.    End If
  657.  
  658. End Sub
  659.  
  660. Sub SSColorDlg(PosX As Long, PosY As Long)
  661.  
  662.     ' If there is a worksheet then load color form
  663.     If Not (MainFrame.ActiveForm Is Nothing) Then
  664.         Load ColorForm
  665.         ColorForm.Left = PosX
  666.         ColorForm.Top = PosY
  667.         ColorForm.Show
  668.     End If
  669.     
  670. End Sub
  671.  
  672. Function SSGetActiveHSS&()
  673.    SSGetActiveHSS& = MainFrame.ActiveForm.SS.SS
  674. End Function
  675.  
  676. Function SSGetActiveSS()
  677.    SSGetActiveSS = MainFrame.ActiveForm.SS
  678. End Function
  679.  
  680. Function SSIsActiveForm%()
  681.  
  682.    Dim bRet%
  683.    
  684.    bRet% = False
  685.    If Forms.Count > 1 Then
  686.       bRet% = True
  687.    End If
  688.    SSIsActiveForm% = bRet%
  689.  
  690. End Function
  691.  
  692. Sub SSMDIOpenFile(OptionalFileName As String)
  693.     
  694.    Dim FileName As String, FileType%
  695.    Dim Er As Integer
  696.  
  697.    FileName = Space$(256)
  698.    If Not SSIsActiveForm Then
  699.       Call C_New
  700.       If Not (MainFrame.ActiveForm Is Nothing) Then
  701.          MainFrame.ActiveForm.SetFocus
  702.       End If
  703.    End If
  704.    
  705.    On Error GoTo Cancel
  706.    
  707.    If OptionalFileName = "" Then
  708.       Er = MainFrame.ActiveForm.SS.OpenFileDlg("Formula One Demo", MainFrame.hWnd, FileName)
  709.    Else
  710.       FileName = OptionalFileName
  711.       Er = 0
  712.    End If
  713.    
  714.    If Er <> 0 Then
  715.       Call ShowSSError(Er)
  716.    Else
  717.       On Error GoTo CantCreateIt
  718.       Dim NewBook As New VCIChildForm
  719.       On Error GoTo UnloadIt
  720.  
  721.       Er = NewBook.SS.Read(FileName, FileType)
  722.       NewBook.SS.TableName = FileName
  723.       NewBook.Caption = FileName
  724.       NewBook.Visible = True
  725.       NewBook.SS.Tag = FileType
  726.       Exit Sub
  727.  
  728. Cancel:
  729.       If Er <> 23 Then
  730.          Call ShowSSError(Er)
  731.       End If
  732.       Exit Sub
  733.       
  734. CantCreateIt:
  735.       MsgBox "Unable to create " & FileName
  736.       Exit Sub
  737.  
  738. UnloadIt:
  739.       Unload NewBook
  740.       MsgBox "Unable to load " & FileName
  741.       
  742.       Exit Sub
  743.     End If
  744.  
  745. End Sub
  746.  
  747. Sub SSMDISaveAsFile()
  748.  
  749.    Dim FileName As String
  750.    Dim Er As Integer
  751.    Dim FileType As Integer
  752.  
  753.    FileName = Space$(256)
  754.    On Error GoTo Cancel
  755.    Er = MainFrame.ActiveForm.SS.SaveFileDlg("Formula One Demo", FileName, FileType)
  756.     
  757.    If Er <> 0 Then
  758.       Call ShowSSError(Er)
  759.    Else
  760.       On Error GoTo CantWriteIt
  761.       MainFrame.ActiveForm.SS.Write FileName, FileType
  762.       MainFrame.ActiveForm.SS.TableName = FileName
  763.       MainFrame.ActiveForm.Caption = FileName
  764.       MainFrame.ActiveForm.SS.Tag = FileType
  765.       Exit Sub
  766.  
  767. Cancel:
  768.    If Er <> 23 Then
  769.       Call ShowSSError(Er)
  770.    End If
  771.    Exit Sub
  772.    
  773. CantWriteIt:
  774.       MsgBox "Unable to write " & FileName
  775.       Exit Sub
  776.    End If
  777. End Sub
  778.  
  779. Sub UpdateTextAndFillColors()
  780.  
  781.     Dim SS As Object
  782.  
  783.     '' This procedure keeps the colors updated on the toolbar
  784.     Set SS = MainFrame.ActiveForm.SS
  785.     MainFrame.lblTextColor.BackColor = SS.PaletteEntry(CurrentTextColorIndex)
  786.     MainFrame.lblFillColor.BackColor = SS.PaletteEntry(CurrentFillColorIndex)
  787.  
  788. End Sub
  789.  
  790.  
  791.